#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
struct Stu
{
	int id,cn,math,en,total;
}student[310];
bool cmpStu(const Stu& a,const Stu& b)
{
	if (a.total != b.total)
		return a.total > b.total;
	else if (a.cn != b.cn)
		return a.cn > b.cn;
	else
		return a.id < b.id;
}
int main() 
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		student[i].id = i;
		scanf("%d%d%d", &student[i].cn, &student[i].math, &student[i].en);
		student[i].total = student[i].cn + student[i].math + student[i].en;
	}
	sort(student +1, student + n + 1, cmpStu);
	for (int i = 1; i <= 5; i++)
	{
		printf("%d %d\n", student[i].id, student[i].total);
	}
	return 0;
}